<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css">
    <link rel="stylesheet" href="__PUBLIC__/static/css/style.css">
    <link rel="icon" href="__PUBLIC__/static/image/code.png">
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body class="body">

<form class="layui-form" action="" method="post" id="addform">
  <div class="layui-form-item">
    <label class="layui-form-label">角色</label>
    <div class="layui-input-block">
      <input type="text" class="layui-input" lay-verify="required" name="names" placeholder="请输入角色名，多个角色间以逗号分隔" onkeyup="value=value.replace(/，/ig,',')">
    </div>
  </div>

	<div class="layui-form-item">
        <label class="layui-form-label">福利类型</label>
        <div class="layui-input-inline">
            <select name="type" lay-verify="required" lay-search="">
                {foreach $type as $key=>$vo}
            	<option value="{$vo.id}">{$vo.name|raw}</option>
                {/foreach}
            </select>
        </div>
	</div>
    <div class="layui-form-item">
        <label class="layui-form-label">发放数量</label>
        <div class="layui-input-block">
            <input type="number" name="num" lay-verify="required" class="layui-input" min="1">
        </div>
    </div>

      <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <input type="text" name="remark" class="layui-input">
        </div>
    </div>

  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>
 

          
<script src="__PUBLIC__/layui/layui.js" charset="utf-8"></script>
<script src="__ADMIN__/js/comm.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'admin','formSelects'], function() {
      var form = layui.form,
        layer = layui.layer,
        $ = layui.$, //重点处
        admin = layui.admin,
        formSelects = layui.formSelects;

      //自定义验证规则
      form.verify({
        name: function(value) {
          if (value.length < 2) {
            return '标题至少得2个字符啊';
          }
        }
      });

      function handlerVals(arr) {
        var str = '';
        $.each(arr, function(i, obj) {
            str += obj.name + ',';
        });
        str = str.substr(0, (str.length - 1));
        $("input[name='names']").val(str);
        console.log(str);
      }

//https://www.cnblogs.com/jingliwufadaodai/p/5756018.html

      //创建一个编辑器

      //监听指定开关
      // form.on('submit(demo1)', function(data) {
      //   $.post('{:url('add')}', $('#addform').serialize(),
      //     function(data) {
      //       if (data.code == 1) {
      //         layer.alert(data.msg, {
      //           skin: 'layui-layer-molv' //样式类名
      //             ,
      //           closeBtn: 0
      //         }, function() {
      //           location.href = data.url;
      //         });
      //       } else {
      //         layer.msg(data.msg);
      //       }
      //     });
      //   return false;
      // });

        form.on('submit(demo1)', function(data){
            admin.action("{:url('admin/WelfareM/add')}",$("#addform").serialize());
            return false;
        });

    });
</script>

</body>
</html>